﻿using LogisticsTrackingWebApi_V3.Models;
using LogisticsTrackingWebApi_V3.Services;

namespace LogisticsTrackingWebApi_V3.ServicesImpl.Providers
{

    /// <summary>
    /// 申通物流查询实现
    /// </summary>
    public class STOExpressProvider : ILogisticsProvider
    {
        public string CompanyCode => "ST";
        public string CompanyName => "申通快递";

        public async Task<LogisticsInfo> QueryTrackingAsync(string trackingNumber)
        {
            // 模拟调用申通API查询
            await Task.Delay(120); // 模拟网络请求延迟

            // 模拟返回结果
            return new LogisticsInfo
            {
                TrackingNumber = trackingNumber,
                CompanyCode = CompanyCode,
                CompanyName = CompanyName,
                Status = "已揽收",
                Traces = new List<LogisticsTrace>
            {
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-3),
                    Location = "杭州市",
                    Description = "快递已揽收"
                },
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-1),
                    Location = "杭州市",
                    Description = "快递正在分拣中"
                }
            }
            };
        }

        public bool MatchTrackingNumber(string trackingNumber)
        {
            // 申通运单号规则：12位或15位数字
            return !string.IsNullOrEmpty(trackingNumber) &&
                   (trackingNumber.Length == 12 || trackingNumber.Length == 15) &&
                   long.TryParse(trackingNumber, out _);
        }
    }
}
